﻿using System;
using umbraco.DataLayer;

namespace UComment.Installer
{
    public class ExecuteNonQuery : umbraco.interfaces.IPackageAction
    {
        #region IPackageAction Members

        public string Alias()
        {
            return "ucomment_executeNonQuery";
        }

        public bool Execute(string packageName, System.Xml.XmlNode xmlData)
        {

            string statement = xmlData.SelectSingleNode("//Sqlserver").InnerText;

            if (umbraco.GlobalSettings.DbDSN.ToLower().Contains("datalayer=mysql"))
            {
                statement = xmlData.SelectSingleNode("//MySQL").InnerText;
            }
            else if (umbraco.GlobalSettings.DbDSN.ToLower().Contains("vistadb,vistadb"))
            {
                statement = xmlData.SelectSingleNode("//VistaDB").InnerText;
            }

            var sqlHelper = DataLayerHelper.CreateSqlHelper(umbraco.GlobalSettings.DbDSN);
            sqlHelper.ExecuteNonQuery(statement);

            return true;
        }

        public System.Xml.XmlNode SampleXml()
        {
            throw new NotImplementedException();
        }

        public bool Undo(string packageName, System.Xml.XmlNode xmlData)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

}
